import Sequelize from 'sequelize';

import { dbLogger } from '../logger';
import config from '../config/environment/development';

const sequelize = new Sequelize(`${config.mysql.host}/ac`, {
  define: {
    freezeTableName: true,
  },
  typeValidation: true,
  benchmark: true,
  timezone: '+08:00',
  logging: (l, t) => {
    if (t > 500) {
      dbLogger.error({ const: t, message: l, logType: 'db' });
    } else if (t > 100) {
      dbLogger.warn({ const: t, message: l, logType: 'db' });
    } else {
      dbLogger.info({ const: t, message: l, logType: 'db' });
    }
  },
});

export { sequelize };
